home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Provider.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  144 lines

  1. /*
  2.  * @(#)Provider.java    1.21 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. import java.io.*;
  18. import java.util.*;
  19.  
  20. /**
  21.  * This class represents a "provider" for the
  22.  * Java Security API.  A provider implements some or all parts of
  23.  * Java Security, including:<ul>
  24.  *
  25.  * <li>Algorithms (such as DSA, RSA, MD5 or SHA-1).
  26.  *
  27.  * <li>Key generation and management facilities (such as for
  28.  * algorithm-specific keys).
  29.  *
  30.  * </ul>
  31.  *
  32.  * <p>Each provider has a name and a version number, and is configured
  33.  * in each runtime it is installed in. 
  34.  * 
  35.  * <p>There is a default provider that comes standard with the JDK. It is
  36.  * called the SUN Provider.
  37.  * 
  38.  * See <a href =
  39.  * "../guide/security/CryptoSpec.html#Provider">The Provider Class</a> 
  40.  * in the "Java Cryptography Architecture API Specification & Reference"
  41.  * for information about how providers work and how to install them.
  42.  * 
  43.  * @version     1.19, 01/30/97
  44.  * @author Benjamin Renaud */
  45.  
  46. public abstract class Provider extends Properties {
  47.  
  48.     private String name;
  49.     private String info;
  50.     private double version;
  51.  
  52.     /**
  53.      * Constructs a provider with the specified name, version number,
  54.      * and information.
  55.      *
  56.      * @param name the provider name.
  57.      *
  58.      * @param version the provider version number.
  59.      * 
  60.      * @param info a description of the provider and its services.
  61.      */
  62.     protected Provider(String name, double version, String info) {
  63.     this.name = name;
  64.     this.version = version;
  65.     this.info = info;
  66.     }
  67.  
  68.     /**
  69.      * Constructs a provider with the specified name. Assigns it
  70.      * version 1.0.
  71.      *
  72.      * @param name the provider name.  
  73.      */
  74.     Provider(String name) {
  75.     this(name, 1.0, "no information available");
  76.     }
  77.  
  78.     /**
  79.      * Returns the name of this provider.     
  80.      * 
  81.      * @return the name of this provider.
  82.      */
  83.     public String getName() {
  84.     return name;
  85.     }
  86.  
  87.     /**
  88.      * Returns the version number for this provider.     
  89.      * 
  90.      * @return the version number for this provider.
  91.      */
  92.     public double getVersion() {
  93.     return version;
  94.     }
  95.  
  96.     /**
  97.      * Returns a human-readable description of the provider and its
  98.      * services.  This may return an HTML page, with relevant links.
  99.      *
  100.      * @return a description of the provider and its services.  
  101.      */
  102.     public String getInfo() {
  103.     return info;
  104.     }
  105.  
  106.  
  107.     static Provider loadProvider(String name) {
  108.     
  109.     try {
  110.         Class cl = Class.forName(name);
  111.         Object instance = cl.newInstance();
  112.  
  113.         if (instance instanceof Provider) {
  114.         return (Provider)instance;
  115.         }
  116.  
  117.     } catch (Exception e) {
  118.         debug("error loading provider " + name, e);
  119.     }
  120.     return null;
  121.     }
  122.  
  123.  
  124.     /**
  125.      * Returns a string with the name and the version number
  126.      * of this provider.     
  127.      * 
  128.      * @return the string with the name and the version number
  129.      * for this provider.
  130.      */
  131.     public String toString() {
  132.     return name + " version " + version;
  133.     }
  134.  
  135.     private static void debug(String msg) {
  136.     Security.debug(msg);
  137.     }
  138.  
  139.     private static void debug(String msg, Throwable t) {
  140.     Security.debug(msg, t);
  141.     }
  142. }
  143.  
  144.